/**
 * TabVD is a Virtual Desktop Client/Server designed specifically for connecting
 * from Tablet like devices.
 *
 * Copyright (C) 2011 Subhabrata Ghosh
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * DateTime.h
 *
 *  Created on: May 24, 2011
 *      Author: subhagho
 */

#ifndef DATETIME_H_
#define DATETIME_H_

#include <string>
#include <time.h>
#include <vector>

#define _DEFAULT_DATE_FORMAT_ "%m-%d-%Y %X"

namespace tabvd {
	/**
	 * %a	Abbreviated weekday name *	Thu
	 * %A	Full weekday name *	Thursday
	 * %b	Abbreviated month name *	Aug
	 * %B	Full month name *	August
	 * %c	Date and time representation *	Thu Aug 23 14:55:02 2001
	 * %d	Day of the month (01-31)	23
	 * %H	Hour in 24h format (00-23)	14
	 * %I	Hour in 12h format (01-12)	02
	 * %j	Day of the year (001-366)	235
	 * %m	Month as a decimal number (01-12)	08
	 * %M	Minute (00-59)	55
	 * %p	AM or PM designation	PM
	 * %S	Second (00-61)	02
	 * %U	Week number with the first Sunday as the first day of week one (00-53)	33
	 * %w	Weekday as a decimal number with Sunday as 0 (0-6)	4
	 * %W	Week number with the first Monday as the first day of week one (00-53)	34
	 * %x	Date representation *	08/23/01
	 * %X	Time representation *	14:55:02
	 * %y	Year, last two digits (00-99)	01
	 * %Y	Year	2001
	 * %Z	Timezone name or abbreviation	CDT
	 * %%	A % sign	%
	 * The specifiers whose description is marked with an asterisk (*) are locale-dependent.
	 */
	class DateTime {
		public:
			/**
			 * Default Constructor - Initializes to current time.
			 */
			DateTime();
			/**
			 * Initialize the instance using the specified value (ticks).
			 */
			DateTime(long);
			/**
			 * Copy constructor.
			 */
			DateTime(DateTime &);
			/**
			 * Virtual Distructor
			 */
			virtual ~DateTime();

			/**
			 * Get the string representation for the date instance.
			 * Default Format : %m-%d-%Y %X
			 */
			std::string* toString();
			/**
			 * Get the string representation for the date instance
			 * using the specified format.
			 */
			std::string* toString(std::string);

			/**
			 * Get the number of seconds since Epoch.
			 */
			long getTimestamp();

			/**
			 * Get the difference in seconds between
			 * the two dates.
			 */
			long diff(DateTime &);

			/**
			 * Reset the datetime to the current time.
			 *
			 */
			DateTime* now();
		private:
			time_t timestamp;
			struct tm* timeinfo;
			char* buffptr;
			size_t sz_buffptr;

			/**
			 * Vector used to store all the allocated string pointers.
			 * Will be cleared at the end.
			 */
			std::vector<std::string *>* usedBuffers;

			void init();
	};

}

#endif /* DATETIME_H_ */
